package cn.com.qingz.modules.user.controller;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.qingz.core.constantes.SystemConstantes;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import cn.com.qingz.core.model.DefaultResp;
import cn.com.qingz.modules.user.vo.*;
import cn.com.qingz.modules.user.service.*;
import cn.com.qingz.modules.user.model.*;
import cn.com.qingz.core.exception.DicmfException;


/**
 * @author codeGen
 */
@Controller
@RequestMapping("billgoods/*")
public class BillGoodsController {

	@Resource
	private BillGoodsService  billgoodsService;
	
	
	/**
	 * 保存商品清单
	 * @param  
	 * @return
	 */
	@RequestMapping("save")
	@ResponseBody
	public DefaultResp<String> save(BillGoods   entity ){
		 DefaultResp<String>  res = new  DefaultResp<String>();
		 try {
			  billgoodsService.doAddOrUpdate( entity);
		 } catch (org.springframework.dao.DuplicateKeyException e) {
			 throw new DicmfException(SystemConstantes.ERROR, "商品清单编码已经存在");
		 }
	     return res; 
	}
	
	
	
	/**
	 * 分页查询
	 * @param condition
	 * @param offset
	 * @param page 页码
	 * @return rows 每页行数
	 */
	@RequestMapping("queryForPage")
	@ResponseBody
	public Map<String,Object> queryByPage(BillGoodsSearchCondition  condition,@RequestParam(required = false,defaultValue = "0") int page,
										    @RequestParam(required = false,defaultValue = "10") int rows){
		 PageList<BillGoods>  list =  billgoodsService.queryForPage(condition, page, rows);
		 Map<String,Object>  res = new HashMap<String,Object>();
		 res.put("total", list.getPaginator().getTotalCount());
		 res.put("rows", list);
		 return res;
	}
	
	


}